// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import Vue from 'vue'
import App from './App'
import router from './router'
import { Toast } from 'vant';

// import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
// Vue.use(ElementUI);

// import { HappyScroll } from 'vue-happy-scroll'
// import 'vue-happy-scroll/docs/happy-scroll.css'
// Vue.component('happy-scroll', HappyScroll)

import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)


axios.interceptors.request.use(
	config => {
		// if (localStorage.getItem("token") != null) {
		//   config.headers["token"] = localStorage.getItem("token");
		// }
		config.headers["token"] = localStorage.getItem("token");
		return config;
	},
	err => Promise.reject(err)
);
axios.interceptors.response.use(
	response => {  
		if (response.status === 200) {   
			return Promise.resolve(response); 
		} else {            
			return Promise.reject(response);        
		}    
	},
	error => {      
		if(error.response.status == 401){
			
			localStorage.clear()
			
			let weixinhao = ""
			if (process.env.NODE_ENV === "development") {
				// weixinhao = 'wx610896f610be8ab1'
				weixinhao = 'wxf7dc12c553c8f869'
				
			}
			if (process.env.NODE_ENV === "test") {
				weixinhao = 'wxf7dc12c553c8f869'
			}
			if (process.env.NODE_ENV === "production") {
				weixinhao = 'wxf7dc12c553c8f869'
			}
			
			
			let wxUrl = window.location.origin + '/mobile3/login'
			      console.log(wxUrl)   
			      console.log(encodeURIComponent(wxUrl))   
			      console.log(weixinhao)   
				 
			var url =
			        "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + weixinhao +
			        "&redirect_uri=" + encodeURIComponent(wxUrl) + //这里放当前页面的地址
			        "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
			
			var ua = navigator.userAgent.toLowerCase();
			　　var isWeixin = ua.indexOf('micromessenger') != -1;
				console.log(isWeixin)
			　　if (isWeixin) {
				// 微信登录
					window.location.href = url;
					// alert('---')
					// alert(url)
			　　}else{
				//手动登录
			   　　 window.location.href = window.location.origin + '/mobile3/denglu'
			　　}
			
			
			
			// router.push({path:'/login'})
		}else{
			Toast({
			  message: error.response.data.message,
			  position: 'bottom',
			}); 
		}
		// return Promise.reject(error.response);
	}
)


// if (process.env.NODE_ENV === "development") {
// 	Vue.prototype.url = '/api'
// }else{
// 	Vue.prototype.url = window.location.origin + '/api'
// }

if (process.env.NODE_ENV === "development") {
	// Vue.prototype.url = 'http://test.91haoka.com:8080'
	Vue.prototype.url = 'http://iot.91haoka.com/api3'
	
}
if (process.env.NODE_ENV === "test") {
	// Vue.prototype.url = 'http://iot.91haoka.com/api/'
	Vue.prototype.url = 'http://test.91haoka.com:8080'
	
}
if (process.env.NODE_ENV === "production") {
	Vue.prototype.url = window.location.origin + '/api3'
}


Vue.config.productionTip = false

Vue.filter('qu0',(val)=>{
	if(!val){
		return ''
	}
    return val.toFixed(2)
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
